package com.congee02.ticket;

/**
 * @author congee02
 * @date 1/31/2023 6:32 PM
 */
public class SellTicketExtendThreadTest {

    public static void main(String[] args) {
        SellTicketExtendThread windows01 = new SellTicketExtendThread("窗口01");
        SellTicketExtendThread windows02 = new SellTicketExtendThread("窗口02");
        SellTicketExtendThread windows03 = new SellTicketExtendThread("窗口03");
        windows01.start();
        windows02.start();        
        windows03.start();
    }

    private static class SellTicketExtendThread extends Thread {
        
        private static int ticketNum = 100;

        public SellTicketExtendThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            while (ticketNum > 0) {
                try {
                    sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(currentThread().getName() + " 售出一张票，剩余票数: " + -- ticketNum);
            }
        }
    }
    
}

